<?php

use Phinx\Migration\AbstractMigration;

class FillDynamicMenuRoute extends AbstractMigration
{
    public function up()
    {
        $auditModule = $this->fetchRow("select id FROM menu_module WHERE code='audit' LIMIT 1");
        $projectManageModule = $this->fetchRow("select id from menu_module where  code='project_manage' limit 1");
        $routeList = [
            [
                'name' => '审片',
                'code' => 'examine',
                'icon' => 'el-icon-warning',
                'route' => '/profile/examine',
                "is_show" => "no",
                "type" => "normal",
                "menu_module_id" => $auditModule['id'],
            ],
            [
                'name' => '剧本',
                'code' => 'story',
                'icon' => 'el-icon-notebook-2',
                'route' => '/profile/asset?asset_code=story',
                "is_show" => "yes",
                "type" => "dynamic",
                "menu_module_id" => $projectManageModule['id'],
            ],
            [
                'name' => '资产',
                'code' => 'asset',
                'icon' => 'el-icon-grape',
                'route' => '/profile/asset?asset_code=asset',
                "is_show" => "yes",
                "type" => "dynamic",
                "menu_module_id" => $projectManageModule['id'],
            ],
            [
                'name' => '关卡',
                'code' => 'level',
                'icon' => 'el-icon-folder-opened',
                'route' => '/profile/asset?asset_code=level',
                "is_show" => "yes",
                "type" => "dynamic",
                "menu_module_id" => $projectManageModule['id'],
            ],
            [
                'name' => '序列',
                'code' => 'sequence',
                'icon' => 'el-icon-video-camera',
                'route' => '/profile/asset?asset_code=sequence',
                "is_show" => "yes",
                "type" => "dynamic",
                "menu_module_id" => $projectManageModule['id'],
            ],
            [
                'name' => '镜头',
                'code' => 'shot',
                'icon' => 'el-icon-camera-solid',
                'route' => '/profile/asset?asset_code=shot',
                "is_show" => "yes",
                "type" => "dynamic",
                "menu_module_id" => $projectManageModule['id'],
            ], [
                'name' => '实体导入',
                'code' => 'entity_excel',
                'icon' => 'el-icon-eleme',
                'route' => '/profile/excel',
                "is_show" => "no",
                "type" => "normal",
                "menu_module_id" => $projectManageModule['id'],
            ],
            [
                'name' => 'cvs导入',
                'code' => 'entity_papa_parse',
                'icon' => 'el-icon-eleme',
                'route' => '/profile/papaParse',
                "is_show" => "no",
                "type" => "normal",
                "menu_module_id" => $projectManageModule['id'],
            ]
        ];

        foreach ($routeList as $route) {
            $route['uuid'] = create_uuid();
            $this->table("menu_route")->insert($route)->save();
        }
    }

    public function down()
    {
        $this->execute("delete from menu_route where code in ('entity_papa_parse','entity_excel','shot','sequence','level','asset','story','examine')");
    }
}
